Previous | Chapter contents | Next | Book PDF
A script command is a single AppleScript statement. Script commands are what an application receives when it is being scripted. It may receive many of them consecutively, but each one is separate, distinct and complete. Script commands are represented by NSScriptCommand objects in the Yellow Box. Sometimes script commands are instances of NSScriptCommand subclasses; if the command has a default implementation based on KVC, it has a specific NSScriptCommand subclass that implements that default behavior. Or if a command has arguments that need special processing, a subclass might do the processing required to provide the arguments in a useful form. However, NSScriptCommand objects can be used by themselves, without the need for subclassing.
An NSScriptCommand has an object specifier that identifies the receiver (or receivers) of the command and can have another object specifier for any arguments defined by the command. Command arguments can be actual values or object specifiers that identify where to find the actual values within the application's object hierarchy.
A scriptable class declares what commands it supports. For commands that have a default implementation, scriptable classes can choose to use it, or they can choose to implement the behavior required by the command themselves. For commands without default implementations, scriptable objects must implement and specify a method that handles the command.
It could seem somewhat odd that script commands are separate from the classes that support them, but this is the nature of AppleScript. AppleScript wants to have a small set of commands that act on a wide set of objects and therefore it defines the commands separately. At least at first, this seems at odds with object-oriented design where you want the behavior and the data rolled up into an a single entity: an object. However, there are some advantages to having them separate, even though the issue is to some degree forced on the frameworks by AppleScript. Having them separate gives the Yellow Box frameworks the ability to support default implementations for commands that are generic enough to be implementable through KVC.
Previous | Chapter contents | Next | Book PDF